package com.nf.mapper;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.nf.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Map;

@Repository(value = "testMapperImpl2")
public class TestMapperImpl2 implements TestMapper {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Student getStudent() {
        try{
            System.out.println("jdbcTemplate:   " +jdbcTemplate);
            Map<String,Object> studentMap = jdbcTemplate.queryForMap("select * from student");
            System.out.println( studentMap );
            Student student = new Student();
            student.setName(  (String) studentMap.get("name")  );
            student.setAge(  (Integer) studentMap.get("age")  );
            return student;

        }catch (Exception e){
            return null;
        }
    }

    @Override
    public boolean delStudent() {
        return false;
    }

    @Override
    public boolean addStudent() {
        return false;
    }
}
